<template>
  <view class="container">
    <z-paging
      ref="paging"
      v-model="itemList"
      @query="queryList"
      :fixed="true"
      :auto="false"
      :auto-show-back-to-top="true"
      :empty-view-img="`${getImageUrl('empty.png')} `"
      empty-view-text="暂无订单数据~"
      :empty-view-img-style="imgStyle"
    >
      <view slot="top">
        <u-navbar height="50" title="退款订单" title-size="36" title-color="#333"></u-navbar>

        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <view class="goodsItemView">
        <view
          class="itemView"
          v-for="(item, index1) in itemList"
          :key="index1"
          @click="onOrderDetail(item)"
        >
          <view class="order-top">
            <view class=""> 交易单号：{{ item.no }} </view>
            <view v-if="item.status == 10" class="order-top-tip"> 客户申请退款 </view>
            <view v-else-if="item.status == 20" class="order-top-tip"> 待买家返货 </view>

            <view v-else-if="item.status == 30" class="order-top-tip"> 待卖家收货 </view>
            <view v-else-if="item.status == 40" class="order-top-tip"> 确认退款 </view>
            <view v-else-if="item.status == 50" class="order-top-tip"> 已完成 </view>
            <view v-else-if="item.status == 61" class="order-top-tip"> 卖家取消售后 </view>
            <view v-else-if="item.status == 62" class="order-top-tip"> 卖家拒绝售后 </view>
            <view v-else-if="item.status == 63" class="order-top-tip"> 卖家拒绝收货 </view>
          </view>

          <view class="order-goods">
            <u-icon class="goods-img" :name="item.picUrl" size="160"></u-icon>
            <view class="orde-riget">
              <view class="goods-title">
                {{ item.spuName }}
              </view>
              <view class="goods-speci">
                <!-- <text>{{item.properties[0]?.valueName}}</text> -->
                <text class="goods-num">x{{ item.count }}</text>
              </view>
              <view class="goods-price">
                <!-- ¥{{(item2.price * 0.01).toFixed(2)}} -->
              </view>
            </view>
          </view>
          <view class="price-total">
            申请退款金额：<text style="color: #f54831"
              >¥{{ (item.refundPrice * 0.01).toFixed(2) }}</text
            >
          </view>

          <view class="btn-group" v-if="item.status == 10">
            <view @click.stop.prevent="onOrderDetail(item)" class="solid-btn btn">
              查看退款详情
            </view>
          </view>

          <view class="btn-group" v-else-if="item.status == 20 || item.status == 30">
            <view
              v-if="item.status == 30"
              @click.stop.prevent="onReceive(item)"
              class="hollow-btn btn"
            >
              确认收货
            </view>
            <view
              v-if="item.status == 30"
              @click.stop.prevent="onCancelReceive(item)"
              class="hollow-btn btn"
            >
              拒绝收货
            </view>
            <view class="hollow-btn btn"> 查看物流 </view>
          </view>
          <view class="btn-group" v-if="item.status == 40">
            <view @click.stop.prevent="onMerConfirm(item)" class="solid-btn btn"> 确认退款 </view>
          </view>
          <!-- <view class="btn-group" v-else-if="item.status == 20 || item.status == 30" >
						<view class="hollow-btn btn">
							同意退款申请
						</view>
					</view> -->
        </view>
      </view>
    </z-paging>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imgStyle: {
        width: '12rem'
      },
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部',
          status: ''
        },
        {
          name: '待处理',
          status: 0
        },
        {
          name: '待发货',
          status: 10
        },
        {
          name: '已收货',
          status: 11
        },
        {
          name: '待退款',
          status: 12
        },
        {
          name: '已完成',
          status: 14
        }
      ],
      itemList: [],
      order_id: ''
    }
  },
  onLoad(res) {
    this.queryList()
  },
  onShow() {
    let self = this
    this.$nextTick(function () {
      //self.onOrderLoad(self.current, null, true);
    })
  },
  methods: {
    queryList(pageNo = 1, pageSize = 10) {
      this.$u.get('/app-api/trade/after-sale/seller-page', { pageNo, pageSize }).then((res) => {
        this.$refs.paging.complete(res.data.list)
        console.log(this.itemList)
      })
    },
    confirm(e) {
      uni.dialog.confirm('温馨提示', '确认接单？', () => {
        this.$u.put('/app-api/shop/trade-order/accept', { id: e.id }).then(() => {
          this.$u.toast('成功')
          this.queryList()
        })
      })
    },
    onReceive(e) {
      uni.dialog.confirm('温馨提示', '确认收货？', () => {
        this.$u.put('/app-api/trade/after-sale/receive?id=' + e.id).then(() => {
          this.$u.toast('成功')
          this.queryList()
        })
      })
    },
    cancel(e) {
      uni.dialog.confirm('温馨提示', '拒绝该订单？', () => {
        this.$u.put('/app-api/shop/trade-order/refuse', { id: e.id }).then(() => {
          this.$u.toast('成功')
          this.queryList()
        })
      })
    },
    onCancelReceive(e) {
      uni.dialog.confirm('温馨提示', '拒绝收货？', () => {
        this.$u.put('/app-api/trade/after-sale/refuse', { id: e.id }).then(() => {
          this.$u.toast('成功')
          this.queryList()
        })
      })
    },
    onOrderCancel(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '确定要取消订单吗？', () => {
        self.$u.api.setOrderCancel(item.order.id).then((res) => {
          self.$u.toast('取消成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onMerConfirm(e) {
      uni.dialog.confirm('温馨提示', '确认退款，退款金额将退回用户？', () => {
        this.$u.put('/app-api/trade/after-sale/refund?id=' + e.id).then(() => {
          this.$u.toast('成功')
        })
      })
    },
    onOrderPayment(item) {
      let self = this
      // self.$u.api.setTestPayments({
      // 	order_no: item.order_no,
      // 	openid: uni.getStorageSync('openid')
      // }).then(res => {
      // 	setTimeout(function() {
      // 		self.onOrderLoad(self.current, null, true);
      // 	}, 500);
      // });
      this.$utils.route({
        url: '/goods/payment/payment',
        params: {
          order_id: item.id,
          money: item.pay_price,
          total_weight: item.total_weight,
          delivery_price: item.delivery_price
        }
      })
    },
    onOrderConfrim(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '该订单确认收货吗？', () => {
        self.$u.api.setOrderConfirm(item.id).then((res) => {
          self.$u.toast('收货成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onResellPush(item) {
      this.$utils.route({
        url: '/goods/resell-push/resell-push',
        params: {
          id: item.id
        }
      })
    },
    onPushComment(item) {
      this.$utils.route({
        url: '/other/push-comment/push-comment',
        params: {
          id: item.id
        }
      })
    },
    onOrderDetail(item) {
      //+ item.id + "&id=" +
      this.$utils.route(
        {
          url: '/other/after-sales/after-sales?id=' + item.id + '&status=2'
        },
        false
      )
    },
    routeTo(url) {
      uni.navigateTo({
        url
      })
    }
  }
}
</script>

<style>
@import url('../../goods/order-list/order-list.css');

page {
  height: 100%;
  background: #f0f1f2;
}
</style>
